package demo.repository;

import demo.entity.Department;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 部门 Dao
 *
 * @author 何宇昕
 * @version 1.0
 */
@Repository
public interface DepartmentRepository extends JpaRepository<Department, Long> {
    /**
     * 按 部门id 搜索部门
     *
     * @param departmentId 部门 id
     * @return 部门号为 departmentId 的部门
     */
    Department findDepartmentByDepartmentId(Long departmentId);

    /**
     * 按 公司id 搜索部门
     *
     * @param companyId 公司 id
     * @return 公司号为 companyId 的所有部门
     */
    List<Department> findDepartmentsByCompanyIdAndUsable(Long companyId, Boolean usable);

    /**
     * 按 部门名 和 公司id 搜索部门（全匹配）
     *
     * @param departmentName 部门名
     * @return 部门对象
     */
    List<Department> findByCompanyIdAndDepartmentName(Long companyId, String departmentName);

    /**
     * 通过 部门 id 搜索部门
     *
     * @param departmentId
     * @return
     */
    Department findByDepartmentId(Long departmentId);

    Department findByDepartmentIdAndUsable(Long departmentId, Boolean usable);

    Boolean existsByCompanyIdAndDepartmentName(Long companyId, String departmentName);

    Boolean existsByCompanyIdAndDepartmentNameAndUsable(Long companyId, String departmentName, Boolean usable);

    List<Department> findAllByCompanyIdAndDepartmentNameAndUsable(Long companyId, String departmentName, Boolean usable);
}
